package com.huiyun.project.im.core.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.ImmutableMap;
import com.huiyun.project.im.consts.ImAppConst;
import com.huiyun.project.im.entity.ImApp;
import com.huiyun.project.im.core.mapper.ImAppMapper;
import com.huiyun.project.im.core.service.IImAppService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huiyun.project.im.common.auth.AppPrincipal;
import org.springframework.stereotype.Service;

/**
 * <p>
 * IM应用组 服务实现类
 * </p>
 *
 * @author bogon
 * @since 2020-07-17
 */
@Service
public class ImAppServiceImpl extends ServiceImpl<ImAppMapper, ImApp> implements IImAppService {

    /**
     * 根据服务商信息以及app信息查询app
     *
     * @param appKey
     * @param appSecret
     * @param imSpId
     * @return
     */
    @Override
    public ImApp findImApp(String appKey, String appSecret, String imSpId) {
        return baseMapper.findImApp(ImmutableMap.of("appKey", appKey, "appSecret", appSecret, "imSpId", imSpId));
    }

    @Override
    public AppPrincipal findPrincipal(String appId) {
        return baseMapper.findPrincipal(appId);
    }

    @Override
    public ImApp findByAppKey(String appKey) {
        return this.getOne(Wrappers.query(new ImApp().setAppKey(appKey).setStatus(ImAppConst.STATUS_NORMAL)));
    }
}
